package d20chat;

import java.awt.Color;


public class Terrain {
	
	private String name;
	private Color color;
	
	public Terrain()
	{
		this("",Color.white);
	}
	
	public Terrain(String n)
	{
		this(n,Color.white);
	}
	
	public Terrain(Color c)
	{
		this("",c);
	}
	
	public Terrain(String n, Color c)
	{
		name = n;
		color = c;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public Color getColor() {
		return color;
	}
	
	@Override
	public boolean equals(Object obj) {
		
		return toString().equals(obj.toString());
	}
	
	public String toString()
	{
		return name+"("+color.getRed()+","+color.getGreen()+","+color.getBlue()+")";
	}
	
	public static Terrain parse(String text)
	{
		String name = text.substring(0,	text.indexOf('('));
		text = text.substring(text.indexOf('(')+1);
		int r = Integer.parseInt(text.substring(0, text.indexOf(',')));
		text = text.substring(text.indexOf(',')+1);
		int g = Integer.parseInt(text.substring(0, text.indexOf(',')));
		text = text.substring(text.indexOf(',')+1);
		int b = Integer.parseInt(text.substring(0, text.length()-1));
		text = text.substring(text.indexOf(',')+1);

		return new Terrain(name, new Color(r, g, b));
	}
}
